package com.tnl.app.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.tnl.app.entity.ArticleInfo;
import com.tnl.base.BaseDAO;


@Repository
public class ArticleDAO {
	private static final String SQL_GET_ID = "select * from tb_articleinfo  where id = ?";
	private static final String SQL_GET_TYPE_CONTENT = "SELECT * from tb_articleinfo where type=1 limit ?,?";
	private static final String SQL_GET_TYPE_YRCCONTENT = "SELECT * from tb_articleinfo where type=4 limit ?,?";
	private static final String SQL_GET_ALL = "select * from tb_articleinfo ";
	
	
	public List<ArticleInfo> getALL() {

		return BaseDAO.queryForList(ArticleInfo.class, SQL_GET_ALL);

	}
	
	public ArticleInfo getById(int Id) {
		return  BaseDAO.queryForObject(ArticleInfo.class, SQL_GET_ID, Id);
	}
	//type=1文章类型
	public List<ArticleInfo> getByContent(int offset,Integer pageSize){
		return  BaseDAO.queryForList(ArticleInfo.class, SQL_GET_TYPE_CONTENT,offset,pageSize);
	}
	
	//type=1文章类型
	public List<ArticleInfo> getByYrcContent(int offset,Integer pageSize){
		return  BaseDAO.queryForList(ArticleInfo.class, SQL_GET_TYPE_YRCCONTENT,offset,pageSize);
	}
	final String SQL_GET_ARTDESC_COUNT="SELECT * from tb_articleinfo where status=1 and type=1 ";
	public int getTotalNumForArtByHot(){
		List<ArticleInfo> list = BaseDAO.queryForList(ArticleInfo.class,SQL_GET_ARTDESC_COUNT);
		if(list==null){
			return 0;
		}
		return list.size();
	}
	
	final String SQL_GET_YRCARTDESC_COUNT="SELECT * from tb_articleinfo where status=1 and type=4 ";
	public int getTotalNumForYrcArtByHot(){
		List<ArticleInfo> list = BaseDAO.queryForList(ArticleInfo.class,SQL_GET_YRCARTDESC_COUNT);
		if(list==null){
			return 0;
		}
		return list.size();
	}
	
	final String SQL_GET_ARTICLEINFO = "SELECT * from tb_articleinfo where status=1 and type=1  order by sort desc limit ?,?";
	//status 1生效，type：1是针对文章类型
	public List<ArticleInfo> getArticleByHotList(int offset, int pageSize) {
		List<ArticleInfo> list = BaseDAO.queryForList(ArticleInfo.class,SQL_GET_ARTICLEINFO,offset,pageSize);
		return list;
	}
	
	final String SQL_GET_YRCARTICLEINFO = "SELECT * from tb_articleinfo where status=1 and type=4  order by sort desc limit ?,?";
	//status 1生效，type：3是针对职道文章类型
	public List<ArticleInfo> getYrcArticleByHotList(int offset, int pageSize) {
		List<ArticleInfo> list = BaseDAO.queryForList(ArticleInfo.class,SQL_GET_YRCARTICLEINFO,offset,pageSize);
		return list;
	}
	
	
	final String SQL_GET_HUNTER_ART="SELECT * from tb_articleinfo where status=1 and type=1 and hunterId=? order by sort desc limit ?,?";
	public List<ArticleInfo> getHunterByArts(Integer hunterid,int offset, int pageSize){
		return BaseDAO.queryForList(ArticleInfo.class, SQL_GET_HUNTER_ART, hunterid,offset,pageSize);
	}
	
	final String SQL_GET_HUNTER_ARTS="SELECT * from tb_articleinfo where status=1 and type=1 and hunterId=? order by sort desc";
	public List<ArticleInfo> getHunterArticles(Integer hunterid){
		return BaseDAO.queryForList(ArticleInfo.class, SQL_GET_HUNTER_ARTS, hunterid);
	}
}
